package com.heima.controller;
import com.heima.pojo.dto.SkuClassDTO;
import com.heima.pojo.entity.SkuClass;
import com.heima.result.PageResult;
import com.heima.service.SkuClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/skuClass")
public class SkuClassController {
    @Autowired
    SkuClassService service;

    @PostMapping
    public boolean insertSku(@RequestBody SkuClassDTO dto) {
        service.insertSku(dto);
        return true;
    }

    @GetMapping("/search")
    public PageResult<SkuClass> getSku(SkuClassDTO dto) {
        PageResult<SkuClass> result = service.gitSku(dto);
        return result;
    }

    /**
     * 根据id查询
     *
     * @param classId
     * @return
     */
    @GetMapping("/{classId}")
    public SkuClass selectById(@PathVariable String classId) {
        return service.selectById(classId);
    }

    /**
     * PUT
     */
    @PutMapping("/{classId}")
    public boolean update(@PathVariable("classId") String classId,@RequestBody SkuClassDTO dto ) {
      boolean result =  service.update(classId,dto);
        return result;
    }

    @DeleteMapping("/{classId}")
    public void delete(@PathVariable String classId) {
        service.delete(classId);
    }
}
